/**
 * 
 */
package com.xpec.c4.game.login.async2;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.service.module.account.Account;
import com.xpec.c4.game.login.LoginModule;
import com.xpec.c4.game.login.async.AccountLoginRequestGetAccountData;
import com.xpec.c4.service.h5server.H5ServerOperations;
import com.xpec.c4.service.module.ModuleName;
import com.xpec.c4.service.module.ServerProperties;
import com.xpec.c4.service.module.common.PlayerCommonInfoManager;
import com.xpec.c4.service.server.CloseType;
import com.xpec.c4.service.server.ServerOperations;

/**
 * @author TW15010
 *
 */
public class AccountLoginGetAccountAsync extends DoAfterLoadAccountAsync {
	/** log4j object */
	private static final Log log = LogFactory.getLog(AccountLoginGetAccountAsync.class);

	private AccountLoginRequestGetAccountData data;

	@Override
	public void execute() throws Exception {
		Account account = getLoadAccount();
		
		LoginModule module = (LoginModule) getCurrentModuleServer();

		if (account == null) {
			if (log.isErrorEnabled()) {
				log.error("load account data fail, a:" + getLoadAccountId());
			}
			if (ServerProperties.isTargetModule(PlayerCommonInfoManager.getInstance().getGatewayBySessionId(data.sessionID), ModuleName.H5GATEWAY)) {
				H5ServerOperations.sessionClose(data.sessionID, CloseType.KICK_BY_ERROR, module);
			} else {
				ServerOperations.sessionClose(data.sessionID, CloseType.KICK_BY_ERROR, module);
			}
			return;
		}

		data.account = account;
		module.accountLoginRequestGetAccountResultCallback(data);
	}

	public void setData(AccountLoginRequestGetAccountData data) {
		this.data = data;
	}
}
